package src.test06;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import src.util.ConnectionUtil;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-08-23
 * Time: 10:49
 */
public class Producer {

    private static final String EXCHANGE_NAME = "topic_exchange";

    public static void main(String[] args) throws Exception {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
        Map<String, String> bindMap = new HashMap<>();
        /**
         * quick.orange.rabbit 被队列 Q1Q2 接收到
         * lazy.orange.elephant 被队列 Q1Q2 接收到
         * quick.orange.fox 被队列 Q1 接收到
         * lazy.brown.fox 被队列 Q2 接收到
         * lazy.pink.rabbit 虽然满足两个绑定但只被队列 Q2 接收一次
         * quick.brown.fox 不匹配任何绑定不会被任何队列接收到会被丢弃
         * quick.orange.male.rabbit 是四个单词不匹配任何绑定会被丢弃
         * lazy.orange.male.rabbit 是四个单词但匹配 Q2
         */
        bindMap.put("quick.orange.rabbit","被队列 Q1Q2 接收到");
        bindMap.put("lazy.orange.elephant","被队列 Q1Q2 接收到");
        bindMap.put("quick.orange.fox","被队列 Q1 接收到");
        bindMap.put("lazy.brown.fox","被队列 Q2 接收到");
        bindMap.put("lazy.pink.rabbit","虽然满足两个绑定但只被队列 Q2 接收一次");
        bindMap.put("quick.brown.fox","不匹配任何绑定不会被任何队列接收到会被丢弃");
        bindMap.put("quick.orange.male.rabbit","是四个单词不匹配任何绑定会被丢弃");
        bindMap.put("lazy.orange.male.rabbit","是四个单词但匹配 Q2");
        for (Map.Entry<String, String> entry :bindMap.entrySet()) {
            String key = entry.getKey();
            String message = entry.getValue();
            channel.basicPublish(EXCHANGE_NAME, key, null, message.getBytes());
            System.out.println("生产者发出消息: " + message);
        };

    }

}
